/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sockets.exemplos;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

/**
 *
 * @author andersonribeiro
 */
public class JavaClient {

    public static void main(String[] args) {

        int port = 9999;
        String host = "127.0.0.1";

        try {
            //Esta classe é utilizada para requisitar conexão a um
            //servidor específico e então transmitir dados.
            Socket s = new Socket(host, port);
            System.out.println("Java client connected to server!\n");

            //InputStream i = s.getInputStream();
            //OutputStream o = s.getOutputStream();

            DataInputStream i1 = new DataInputStream(s.getInputStream());
            DataOutputStream o1 = new DataOutputStream(s.getOutputStream());

            String str;
            do {
                byte[] line = new byte[100];
                System.in.read(line);
                //o.write(line);
                //i.read(line);
                o1.write(line);
                i1.read(line);
                str = new String(line);
                System.out.println(str.trim());
            } while (!str.trim().equals("bye"));

            s.close();
            System.out.println("Java client disconnected from server!\n");
        } catch (Exception e) {
            System.out.println(e);
        }

    }
}
